﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Hospital_RevisionHosPur : System.Web.UI.Page
{
    Int64 RHPHsId;
    Int64 RhPSGID;
    Int64 RHPHospiId;
    public Int64 RHPProID;
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumHospitale);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {  
            RHPHsId = Convert.ToInt64(SysFun.IsSQL(Request.QueryString["HsPId"].ToString()));
            RhPSGID = Convert.ToInt64(SysFun.IsSQL(Request.QueryString["SupplyGoodsId"].ToString()));
            RHPProID = Convert.ToInt64(SysFun.IsSQL(Request.QueryString["ProjectId"].ToString()));
            if (!IsPostBack)
            {
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                if (_Account != null)
                {
                    String RHPHospiName = "";
                    RHPHospiId = SysFun.ToLong(_Account.AccountId);
                    RHPHospiName = SysFun.ToTrim(_Account.DWName);
                    String StrSql;
                    if (Request.QueryString["HsPId"] == null && Request.QueryString["SupplyGoodsId"] == null)
                    {
                        Response.Write("<script>window.alter('没有要添加的商品或页面过期，请重新点击！！')</script>");
                    }
                    else
                    {
                        //RHPHsId = Convert.ToInt64(Request.QueryString["HsPId"].ToString());
                        //RhPSGID = Convert.ToInt64(Request.QueryString["SupplyGoodsId"].ToString());
                        //RHPProID = Convert.ToInt64(Request.QueryString["ProjectId"].ToString());

                        Db db = new Db();
                        System.Data.IDataReader dr;
                        StrSql = "Select ProductName,Medicinemodel,Outlookc,CompanyName_SC,CompanyName_TB,GoodsName,Factor,PackUnit,Convert(numeric(20,2),RetailPrice) As RetailPrice,QualityLevels,Convert(numeric(20,2),BidPrice) As BidPrice From SupplyPlan_Goods Where SupplyGoodsId='" + RhPSGID + "'";
                        dr = db.DataReader(StrSql);
                        while (dr.Read())
                        {
                            labProductName.Text = dr["ProductName"].ToString();
                            labMedicinemodel.Text = dr["Medicinemodel"].ToString();
                            labOutlookc.Text = dr["Outlookc"].ToString();
                            labCompanyName_SC.Text = dr["CompanyName_SC"].ToString();
                            labCompanyName_TB.Text = dr["CompanyName_TB"].ToString();
                            labHospitalName.Text = RHPHospiName;
                            labGoodsName.Text = dr["GoodsName"].ToString();
                            labFactor.Text = dr["Factor"].ToString();
                            labPackUnit.Text = dr["PackUnit"].ToString();
                            labRetailPrice.Text = dr["RetailPrice"].ToString();
                         //   LBBidPrice.Text = dr["BidPrice"].ToString();
                            rdoQualityLevels.SelectedValue = SysFun.ToTrim(dr["QualityLevels"]);
                            
                        }
                        dr.Close();
                        dr.Dispose();

                        StrSql = "Select HospitalPurchase.*,SupplyCompany.CompanyName_PS From HospitalPurchase,SupplyCompany Where HsPId=" + RHPHsId + " And HospitalPurchase.Accountid_PS=SupplyCompany.Accountid_PS And HospitalPurchase.ProjectId=" + RHPProID;
                        dr = db.DataReader(StrSql);
                        while (dr.Read())
                        {
                            txtCompanyName_PS.Text = dr["CompanyName_PS"].ToString();
                            txtAccountId_PS.Text = dr["AccountId_PS"].ToString();
                         //   txtPlanPurNum.Text = dr["PlanPurNum"].ToString();
                        //    txtPurchasePrice.Text = dr["PurchasePrice"].ToString();
                       //     txtcontractStartDate.Text = dr["contractStartDate"].ToString();
                       //     txtcontractEndDate.Text = dr["contractEndDate"].ToString();
                        }
                        dr.Close();
                        dr.Dispose();
                        db.Close();

                    }
                }
            }
        }

    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {
         HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
         if (_Account != null)
         {
             RHPHospiId = SysFun.ToLong(_Account.AccountId);
            
                 String SalerId_PS,  PurchasePrice, StrSql;
                 DateTime contractStartDate, contractEndDate;
                
                 if (SysFun.ToTrim(Request.Form["txtAccountId_PS1"]) == "")
                 {
                     SalerId_PS = SysFun.ToTrim(txtAccountId_PS.Text.ToString());
                 }
                 else
                 {
                     SalerId_PS = SysFun.ToTrim(Request.Form["txtAccountId_PS1"]);
                 }
               //  PlanPurNum = SysFun.ToTrim(txtPlanPurNum.Text);
              //   PurchasePrice = SysFun.ToTrim(txtPurchasePrice.Text);

            //     if (txtcontractStartDate.Text != "")
            //         contractStartDate = Convert.ToDateTime(txtcontractStartDate.Text.ToString());
            //     else
           //          contractStartDate = Convert.ToDateTime("2006-1-1");

             //    if (txtcontractEndDate.Text != "")
             //        contractEndDate = Convert.ToDateTime(txtcontractEndDate.Text.ToString());
             //    else
             //        contractEndDate = Convert.ToDateTime("2006-1-1");

                 Db db = new Db();
                 StrSql = "Update HospitalPurchase Set AccountId_PS='" + SalerId_PS + "' Where HsPId='" + RHPHsId + "'";
                 db.Command(StrSql);
                 db.Close();
                 Response.Write("<script>window.alert('保存成功！');</script>");
                 Response.Write("<script>window.opener.location.href=window.opener.location.href;</script>");
                 Response.Write("<script>window.close();</script>");
             }
         
    }


    protected void BtnCancel_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.close();</script>");
    }
}
